package com.jjyu.controller;

import com.jjyu.entity.StoreReview;
import com.jjyu.service.StoreReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/reviews")
public class StoreReviewController {

    @Autowired
    private StoreReviewService storeReviewService;

    @PostMapping
    public ResponseEntity<String> addReview(@RequestBody StoreReview storeReview) {
        storeReviewService.addReview(storeReview);
        return ResponseEntity.ok("评价提交成功");
    }

    @GetMapping("/{restaurantId}")
    public ResponseEntity<List<StoreReview>> getReviews(@PathVariable Integer restaurantId) {
        List<StoreReview> reviews = storeReviewService.getReviewsByRestaurantId(restaurantId);
        return ResponseEntity.ok(reviews);
    }

    @GetMapping("/user/{userId}")
    public ResponseEntity<List<StoreReview>> getUserReviews(@PathVariable Integer userId) {
        List<StoreReview> reviews = storeReviewService.getReviewsByUserId(userId);
        return ResponseEntity.ok(reviews);
    }
}
